package io.renren.modules.back.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.back.entity.GoodsSpecificationEntity;
import io.renren.modules.back.service.GoodsSpecificationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 商品规格接口
 *
 * @author zzh
 * @email 862583291@qq.com
 * @date 2019年4月9日 上午10:40:10
 */
@RestController
@RequestMapping("/back/goodsSpecification")
public class GoodsSpecificationController {
    @Autowired
    private GoodsSpecificationService goodsSpecificationService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("goodsSpecification:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<GoodsSpecificationEntity> goodsSpecificationList = goodsSpecificationService.queryList(query);
        int total = goodsSpecificationService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(goodsSpecificationList, total, query.getLimit(), query.getCurrPage());

        return R.ok().put("data", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("goodsSpecification:info")
    public R info(@PathVariable("id") Integer id) {
        GoodsSpecificationEntity goodsSpecification = goodsSpecificationService.queryObject(id);
        return R.ok().put("data", goodsSpecification);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("goodsSpecification:save")
    public R save(@RequestBody GoodsSpecificationEntity goodsSpecification) {
        goodsSpecificationService.save(goodsSpecification);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("goodsSpecification:update")
    public R update(@RequestBody GoodsSpecificationEntity goodsSpecification) {
        goodsSpecificationService.updateObject(goodsSpecification);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("goodsSpecification:delete")
    public R delete(@RequestBody Integer[]ids) {
        goodsSpecificationService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
